package com.bawei.model_sevent.Activity.Fragemnt;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.bawei.model_sevent.Activity.Activity.MainActivity_zhibo;
import com.bawei.model_sevent.Activity.Adapter.HuoBaoAdapter;
import com.bawei.model_sevent.Activity.Adapter.ShangPingAdapter;
import com.bawei.model_sevent.Activity.Banner.BannerBean;
import com.bawei.model_sevent.Activity.Banner.BannerContent;
import com.bawei.model_sevent.Activity.Banner.BannerModel;
import com.bawei.model_sevent.Activity.Banner.BannerPreson;
import com.bawei.model_sevent.R;
import com.bumptech.glide.Glide;
import com.sunfusheng.marqueeview.MarqueeView;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.config.IndicatorConfig;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.RectangleIndicator;
import com.youth.banner.transformer.AlphaPageTransformer;
import com.youth.banner.transformer.ScaleInTransformer;

import java.util.ArrayList;
import java.util.List;


public class BlankFragment_main extends Fragment implements BannerContent.View {


    private EditText shouSuo;
    private ImageView showSao;
    private Banner banner;
    private MarqueeView marqu;
    private RecyclerView recyHuoren;
    private CheckBox zhibo;
    private RecyclerView recyHuo02;
    private Banner banner02;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_blank_main, container, false);
        shouSuo = inflate.findViewById(R.id.shou_suo);
        showSao = inflate.findViewById(R.id.show_sao);
        banner = inflate.findViewById(R.id.banner);
        marqu = inflate.findViewById(R.id.marqu);
        zhibo = inflate.findViewById(R.id.zhibo);
        banner02 = inflate.findViewById(R.id.banner02);
        recyHuo02 = inflate.findViewById(R.id.recy_huo02);
        recyHuoren = inflate.findViewById(R.id.recy_huoren);
        recyHuo02.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        ArrayList<String> strings = new ArrayList<>();
        strings.add("新用户立减1000元优惠价");
        strings.add("老用户没有");
        //适配文字
        marqu.startWithList(strings);
        // 在代码里设置自己的动画
        marqu.startWithList(strings, R.anim.anim_bottom_in, R.anim.anim_top_out);

        BannerPreson bannerPreson = new BannerPreson(new BannerModel(), this);
        bannerPreson.GetDate("1", "15");
        zhibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MainActivity_zhibo.class);
                startActivity(intent);
            }
        });
        return inflate;
    }


    @Override
    public void initAdapter(List<BannerBean.DataBean> bannerList) {
        recyHuoren.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));
        HuoBaoAdapter huoBaoAdapter = new HuoBaoAdapter(bannerList);
        recyHuoren.setAdapter(huoBaoAdapter);
        ShangPingAdapter shangPingAdapter = new ShangPingAdapter(bannerList);
        recyHuo02.setAdapter(shangPingAdapter);

        banner.setAdapter(new BannerImageAdapter<BannerBean.DataBean>(bannerList) {

            @Override
            public void onBindView(BannerImageHolder holder, BannerBean.DataBean data, int position, int size) {
                Glide.with(holder.imageView).load(data.getPictUrl())
//                        .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(20)))
                        .into(holder.imageView);
            }
        }).addBannerLifecycleObserver(this)
                .setIndicator(new RectangleIndicator(getActivity()))
                .addPageTransformer(new AlphaPageTransformer())
                .setIndicatorSelectedColor(Color.GRAY)
                .setIndicatorHeight(14)
                .setIndicatorGravity(IndicatorConfig.Direction.RIGHT)
                .setIndicatorWidth(14, 14)
                .setIndicatorSpace(14);
        banner02.setAdapter(new BannerImageAdapter<BannerBean.DataBean>(bannerList) {
            @Override
            public void onBindView(BannerImageHolder holder, BannerBean.DataBean data, int position, int size) {
                Glide.with(holder.imageView).load(data.getPictUrl())
//                        .apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(20)))
                        .into(holder.imageView);
            }
        }).addBannerLifecycleObserver(this)
//                .setIndicator(new RectangleIndicator(getActivity()))
                .addPageTransformer(new ScaleInTransformer())
                .setBannerGalleryEffect(40, 20, 80)
                .setIndicatorSelectedColor(Color.BLUE)
                .setIndicatorHeight(20)
                .setIndicatorWidth(5, 20)
                .setIndicatorSpace(20)
                .isAutoLoop(false)
        ;
    }
}